package myJs.myPkg

import myJs.myPkg.jquery._
import slinky.readwrite.ObjectOrWritten

import scala.scalajs.js
import scala.language.implicitConversions
import scala.scalajs.js.JSConverters._
import scala.scalajs.js.ThisFunction1
import scala.scalajs.js.annotation.JSImport


/**
 * Created by yz on 2019/3/14
 */
@js.native
trait TypeaheadJquery extends js.Object {

  def typeahead(options: ObjectOrWritten[TypeaheadOptions]): JQuery = scalajs.js.native

  def typeahead(method: String): JQuery = scalajs.js.native

}

@js.native
@JSImport("Typeahead", JSImport.Namespace)
abstract class Typeahead extends js.Object {

  def query: String = js.native

  def $element: JQuery = js.native

}

case class TypeaheadOptions(
                             source: js.UndefOr[List[String]] = js.undefined,
                             autoSelect: js.UndefOr[Boolean] = js.undefined,
                             updater: js.UndefOr[js.ThisFunction1[Typeahead, String, String]] = js.undefined,
                             highlighter: js.UndefOr[ThisFunction1[Typeahead,String,String]] = js.undefined,
                             matcher: js.UndefOr[js.ThisFunction1[Typeahead, String, AnyVal]] = js.undefined,
                           )


trait TypeaheadJQueryImplicits {
  implicit def implicitTypeaheadJQuery(jq: JQuery) = {
    jq.asInstanceOf[TypeaheadJquery]
  }
}
